package com.blb.socket.demo4;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * BIO客户端
 */
public class BIOClient {

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            connect();
        }
    }

    public static void connect(){
        //创建Socket对象
        try(Socket client = new Socket("127.0.0.1",8888);
            ObjectOutputStream out = new ObjectOutputStream(client.getOutputStream());
            ObjectInputStream in = new ObjectInputStream(client.getInputStream());
        ) {
            //发消息给服务器
            out.writeUTF("Hello我是客户端！！！");
            out.flush();
            //接收服务器消息
            String msg = in.readUTF();
            System.out.println("服务器：" + msg);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
